package com.enhe.gck.fg;

import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import com.enhe.gck.item.ConfigHWANE16627Item;
import com.enhe.gck.pojo.ExchangeDay;
import com.kuangkie.carbon.enun.SortDirection;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.FGRecord;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.ExchangeDayHWANE16821Item; // 模型属性Code

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
@Slf4j
@Repository(value = "hwane16821366042330866425862")
public class ExchangeDayHWANE16821BNB implements SecondRoundImproveFuncGroup{
	@Resource
	private ConfigHWANE16627BNB configHWANE16627BNB;

	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		ExchangeDay info=proRecord.getBean(ExchangeDay.class);
		//TODO 暂去掉验证 之后时间不能添加
//		if(info.getDate().compareTo(new Date())>0){
//			PublicMethod.returnMessage(improveResultFactory, PublicReturn.Recharge_3);
//		};
		if(proRecord.isNew()){
			if(!proRecord.getBooleanValue(ExchangeDayHWANE16821Item.基本属性组_是否系统获取)){
				String value=configHWANE16627BNB.getConfigValue(CarbonEnumKeyValue.参数配置_类型_汇率增减幅度_hlzjfd);
				if(value!=null){
					ExchangeDay exchangeDay=CarbonPanel
							.getRecordQueryFactory(CarbonBaseConstant.每日汇率_mrhl).getProConJunctionFactory()
							.goBack().addSortItem(ExchangeDayHWANE16821Item.基本属性组_日期, SortDirection.DESC).queryABean(ExchangeDay.class);
					if(exchangeDay!=null){
						BigDecimal newValue=PublicMethod.divideBigDecimal(PublicMethod.subtractBigDecimal(info.getValue(),exchangeDay.getValue()),exchangeDay.getValue(),3,null).abs();
						if(PublicMethod.compareToBigDecimal(newValue,value)>0){
							PublicMethod.returnMessage(improveResultFactory, PublicReturn.Recharge_2);
						}
					}
				}
			}
		}

	}

}
